package stu.day25_day32.day28;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class hw3 {
    List<List<Integer>> list = new ArrayList<>();
    List<Integer> arr = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {

        boolean[] bl = new boolean[nums.length];
        Arrays.fill(bl,false);
        return list;
    }

    public List<List<Integer>> permuteUnique(int[] nums) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> arr = new ArrayList<>();
        HashSet<Integer> set = new HashSet<>();
        boolean[] bl = new boolean[nums.length];
        Arrays.fill(bl,false);

        return list;
    }


    public void dfs(int[] nums,List<Integer> arr,boolean[] bl){


        if(arr.size()==nums.length){
            list.add(new ArrayList<>(arr));
        }

        for(int i=0;i<nums.length;i++){
            if(!bl[i]){
                arr.add(nums[i]);
                bl[i]=true;
                dfs(nums,arr,bl);
                bl[i]=false;
                arr.removeLast();
            }
        }
    }


    public void backtrack(int[] nums,List<Integer> arr,boolean[] bl,HashSet<Integer> set,int index){

        if(arr.size()==nums.length){
            list.add(new ArrayList<>(arr));
        }


        for(int i=0;i<nums.length;i++){
            if(!bl[i]){
                if( i > 0 && nums[i] == nums[i - 1] && bl[i-1]){
                    continue;
                }
                //set.contains()
                arr.add(nums[i]);
                bl[i]=true;
                backtrack(nums,arr,bl,set,index);
                bl[i]=false;
                arr.removeLast();
            }
        }

    }



}
